package modulos;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import auxiliary.Constants;
import auxiliary.Database;

public class TableModelConfirmar extends AbstractTableModel {

	Vector cache;
	String[] headers;
	int colCount;

	Database db;

	TableModelConfirmar() {
		cache = new Vector();
	}

	public void updateTable(String dia,String mes,String ano) {
		db = new Database();
		
		cache = new Vector();
		ArrayList<ArrayList<String>> mensualesData = new ArrayList<ArrayList<String>>();

		mensualesData = db.retrieveMensuales(dia,mes,ano);
		db.closeConnection();
		headers = new String[] { "Lote Id", "Nombre Producto",
				"Unidades", "Fases" , "Termina?" };

		colCount = headers.length;

		for (int i = 0; i < mensualesData.size(); i++) {
			String[] list = (Constants.arrayListToString(mensualesData))[i];
			list = Arrays.copyOfRange(list, 1, list.length);
			cache.addElement(list);
		}

		fireTableChanged(null);

	}

	@Override
	public int getColumnCount() {
		return colCount;
	}

	@Override
	public int getRowCount() {
		return cache.size();
	}

	@Override
	public Object getValueAt(int row, int col) {
		return ((String[]) cache.elementAt(row))[col];
	}

	public String getColumnName(int i) {
		return headers[i];
	}

}